package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.Equipment;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.EquipmentService;

@Controller
@RequestMapping("/equipment")
public class EquipmentController {
	
	@Autowired
	private EquipmentService EquipmentService;
	
	@RequestMapping(value = "/operateByEquipment")
	public @ResponseBody ResultBean operateByWorkshop(@RequestBody Equipment equipment) {
		ResultBean resultBean = new ResultBean(true, ' ');
		
		// Determine the new
		if (equipment.getModificationFlag() == IModificationFlags.NEW) {
			resultBean = EquipmentService.save(equipment);
			// Judge update
		} else if (equipment.getModificationFlag() == IModificationFlags.MODIFIED) {
			resultBean = EquipmentService.update(equipment);
			// Judge to delete
		} else if (equipment.getModificationFlag() == IModificationFlags.DELETED) {
			resultBean = EquipmentService.delete(equipment);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/selectEquipBaseInfoData")
	public @ResponseBody List<Equipment> selectEquipBaseInfoData() {
		return EquipmentService.selectEquipBaseInfoData();
		 
	}
	
	@RequestMapping(value = "/selectEquipSpareDaoJuInfo")
	public @ResponseBody List<Equipment> selectEquipSpareDaoJuInfo () {
		return EquipmentService.selectEquipSpareDaoJuInfo();
	}
	@RequestMapping(value = "/selectEquipSpareDaoJuInfoByCode/{code}")
	public @ResponseBody List<Equipment> selectEquipSpareDaoJuInfoByCode (@PathVariable String code) {
		return EquipmentService.selectEquipSpareDaoJuInfoByCode(code);
	}
	

}
